var opinionPrice;

/**
 * 设置结果接收对象
 * @param _opinionPrice
 */
function setModel(_opinionPrice) {
    if (_opinionPrice == undefined || !(_opinionPrice instanceof com.jf.crawl.model.OpinionPrice)) {
        throw new java.lang.Exception("opinionPrice 对象为空");
    }
    log.info("opinionPrice {}", _opinionPrice)
    opinionPrice = _opinionPrice;
}

function crawler() {
    var map = new LinkedHashMap();
    for (var i = 1; i < 5; i++) {
        eachGetYND(i, map)
    }
    if (map != null) {
        for (var string in map) {
            var month = string;
            var price = map[string].trim().replace("%", "");
            if ("30天".equals(month)) {
                opinionPrice.setOneMonth(commonUtil.string2Decimal(price));
            } else if ("45天".equals(month)) {
                opinionPrice.setOneHalfMonth(commonUtil.string2Decimal(price));
            } else if ("60天".equals(month)) {
                opinionPrice.setTwoMonth(commonUtil.string2Decimal(price));
            } else if ("90天".equals(month)) {
                opinionPrice.setThreeMonth(commonUtil.string2Decimal(price));
            } else if ("180天".equals(month)) {
                opinionPrice.setSixMonth(commonUtil.string2Decimal(price));
            } else if ("270天".equals(month)) {
                opinionPrice.setNineMonth(commonUtil.string2Decimal(price));
            } else if ("365天".equals(month)) {
                opinionPrice.setOneYear(commonUtil.string2Decimal(price));
            } else if ("730天".equals(month)) {
                opinionPrice.setTwoYear(commonUtil.string2Decimal(price));
            } else if ("1095天".equals(month)) {
                opinionPrice.setThreeYear(commonUtil.string2Decimal(price));
            }
        }
    }
    return true;
}

//翼龙贷
function eachGetYND(pageNo, map) {
    var url = "https://licai.eloancn.com/pcgway/gateway/v1/01";
    var params = new LinkedHashMap();
    params.put("requesturl", "/appwmps/app004/v2/01");
    params.put("pageNo", String(pageNo));
    params.put("platform", "5");
    params.put("v", String(Math.random()));
    var result = Post(url, null, params);
    var json = JSON.parseObject(result);
    if (json.containsKey("data")) {
        var data = json.getJSONObject("data");
        if (data.containsKey("data")) {
            var jsonArray = JSON.parseArray(data.getString("data"));
            for (var i = 0; i < jsonArray.size(); i++) {
                var eachData = jsonArray.getJSONObject(i);
                //16860期 需要判断日期非今天的不存
                var title = eachData.getString("title").substr(0, 2);
                var totay = getToday();
                if (title == totay) {
                    var strInterestrate = eachData.getString("strInterestrate");
                    var strPhases = eachData.getString("strPhases");
                    var strStatus = eachData.getString("strStatus");
                    var status = eachData.getString("status");
                    if (!map.containsKey(strPhases)) {
                        map.put(strPhases, strInterestrate);
                    }
                } else {
                    log.info("当前产品非今天更新,产品推出,{}", title)
                }
            }
        }
    }
}

function getToday() {
    var date = new Date();
    var day = date.getDate();
    return day;
}